<template>
  <div class="main">
    <el-empty v-show="unsolved.length === 0" :image-size="200"></el-empty>
    <el-table
        v-show="unsolved.length !== 0"
        :data="unsolved"
        style="width: 100%">
      <el-table-column
          label="日期"
          width="270">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.date }}</span>
        </template>
      </el-table-column>
      <el-table-column
          label="专家姓名"
          width="200">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.farmer.name }}</p>
            <p>电话号码: {{ scope.row.farmer.phone }}</p>
            <p>邮箱地址: {{ scope.row.farmer.email }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.farmer.name }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column
          label="问题描述"
          width="480">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.question }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <ShowQuestionForm :row="scope.row"/>
          <el-popover
              placement="top"
              v-model="visible"
              width="160">
            <p>确定删除吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="visible = false">取消</el-button>
              <el-button type="primary" size="mini" @click="handleDelete(scope.$index, scope.row)">确定</el-button>
            </div>
            <el-button
                size="mini"
                type="danger"
                slot="reference">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {mapActions, mapState} from "vuex";
import ShowQuestionForm from "@/components/farmer/ShowQuestionForm";

export default {
  name: "ShowUnsolvedList",
  components:{
    ShowQuestionForm
  },
  data(){
    return {
      visible:false
    }
  },
  methods:{
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      this.delQuestion(row)
    },
    ...mapActions('question',{findAllUnsolved:'findAllUnsolved',delQuestion:"delQuestion"}),
    ...mapActions('farmer',{findFarmerByUid:'findFarmerByUid'}),
  },
  computed:{
    ...mapState('question',['unsolved']),
    ...mapState('farmer',['loginFarmer'])
  },
  async created() {
    await this.findFarmerByUid()
    await this.findAllUnsolved(this.loginFarmer.id)
  },
}
</script>

<style scoped>

</style>